home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Just Call Me Internet
/
Just Call Me Internet.iso
/
prog
/
atari
/
m2
/
cat3src
/
magic
/
d
/
filesys.d
next >
Wrap
Text File
|
1997-10-26
|
19KB
|
411 lines
DEFINITION MODULE FileSys;
(*==============================================================*
* *
* Mint-Binding fr Megamax Modula-2, unter Benutzung der *
* MagicLib von Peter Hellinger. *
* *
* (c) 1992 Dirk Steins *
* *
* Dieses Modul ist Freeware! *
* *
*==============================================================*
* Autor: Dirk Steins *
* erstellt am: 13.8.1992 *
* letzte nderung am: 13.8.1992 *
* Version: 1.0 *
*==============================================================*
* Datum Vers. Autor nderung (Arbeitsbericht) *
*==============================================================*
*
* 13.8.92 1.0 DS Modul erstellt
*
*==============================================================*)
FROM SYSTEM IMPORT BYTE, ADDRESS;
FROM MagicSys IMPORT sCARDINAL, lCARDINAL, sINTEGER, lINTEGER, sBITSET, lBITSET,
Bit0, Bit1, Bit2, Bit3, Bit4, Bit5, Bit6, Bit7, Bit8, Bit9,
Bit10, Bit11, Bit12, Bit13, Bit14, Bit15;
CONST
TOS_SEARCH = 0; (* Bit 0 in flags by DIR *)
(* file types *)
S_IFMT = 0170000; (* mask to select file type *)
S_IFCHR = 0020000; (* BIOS special file *)
S_IFDIR = 0040000; (* directory file *)
S_IFREG = 0100000; (* regular file *)
S_IFIFO = 0120000; (* FIFO *)
S_IMEM = 0140000; (* memory region or process *)
S_IFLNK = 0160000; (* symbolic link *)
(* special bits: setuid, setgid, sticky bit *)
S_ISUID = 04000;
S_ISGID = 02000;
S_ISVTX = 01000;
(* file access modes for user, group, and other*)
S_IRUSR = 0400;
S_IWUSR = 0200;
S_IXUSR = 0100;
S_IRGRP = 0040;
S_IWGRP = 0020;
S_IXGRP = 0010;
S_IROTH = 0004;
S_IWOTH = 0002;
S_IXOTH = 0001;
DEFAULT_DIRMODE = 0777;
DEFAULT_MODE = 0666;
(* file locking *)
F_RDLCK = (* O_RDONLY*) 1;
F_WRLCK = (* O_WRONLY *) 2;
F_UNLCK = 3;
FS_KNOPARSE = 0; (* kernel shouldn't do parsing *)
FS_CASESENSITIVE = 1; (* file names are case sensitive *)
FS_NOXBIT = 2; (* if a file can be read, it can be executed *)
TYPE
FILESYSPTR = POINTER TO FILESYS;
DEVDRVPTR= POINTER TO DEVDRV;
FILEPTR = POINTER TO FILE;
DIRPTR = POINTER TO DIR;
FCOOKIEPTR = POINTER TO FCOOKIE;
FCOOKIE = RECORD
fs : FILESYSPTR;
dev : sCARDINAL;
aux : sCARDINAL;
index : lINTEGER;
END;
DIR = RECORD
fc : FCOOKIE;
index : sCARDINAL;
flags : sBITSET;
fsstuff: ARRAY [0..59] OF BYTE;
END;
XATTR = RECORD
mode : sCARDINAL; (* oder sBITSET *)
index : lINTEGER;
dev : sCARDINAL;
reserved1 : sCARDINAL;
nlink : sCARDINAL;
uid : sCARDINAL;
gid : sCARDINAL;
size : lINTEGER;
blksize: lINTEGER;
nblocks: lINTEGER;
mtime,
mdate : sINTEGER;
atime,
adate : sINTEGER;
ctime,
cdate : sINTEGER;
attr : sINTEGER;
reserved2 : sINTEGER;
reserved3 : ARRAY [0..1] OF lINTEGER;
END;
FILE = RECORD
links : sINTEGER; (* number of copies of this descriptor *)
flags : sBITSET; (* file open mode and other file flags *)
pos : lINTEGER; (* position in file *)
devinfo: lINTEGER; (* device driver specific info *)
fc : FCOOKIE; (* file system cookie for this file *)
dev : DEVDRVPTR; (* device driver that knows how to deal with this *)
next : FILEPTR; (* link to next fileptr for this file *)
END;
(* lock structure *)
FLOCK = RECORD
l_type : sINTEGER; (* type of lock *)
l_whence: sINTEGER; (* SEEK_SET, SEEK_CUR, SEEK_END *)
l_start: lINTEGER; (* start of locked region *)
l_len : lINTEGER; (* length of locked region *)
l_pid : sINTEGER; (* pid of locking process
(F_GETLK only) *)
END;
(* LOCK structure used by the kernel internally *)
iLOCK = POINTER TO LOCK;
LOCK = RECORD
l : FLOCK;
next : iLOCK;
reserved : ARRAY [0..3] OF lINTEGER;
END;
DEVDRV = RECORD
open : PROCEDURE (FILEPTR) : lINTEGER;
write : PROCEDURE (FILEPTR, ADDRESS, lINTEGER) : lINTEGER;
read : PROCEDURE (FILEPTR, ADDRESS, lINTEGER) : lINTEGER;
lseek : PROCEDURE (FILEPTR, sINTEGER, sINTEGER): lINTEGER;
ioctl : PROCEDURE (FILEPTR, sINTEGER, ADDRESS) : lINTEGER;
datime : PROCEDURE (FILEPTR, VAR sINTEGER, BOOLEAN) : lINTEGER;
close : PROCEDURE (FILEPTR, sINTEGER) : lINTEGER;
select : PROCEDURE (FILEPTR, lINTEGER, sINTEGER) : lINTEGER;
unselect: PROCEDURE (FILEPTR, lINTEGER, sINTEGER): lINTEGER;
reserved: ARRAY [0..3] OF lINTEGER;
END;
FILESYS = RECORD
next : FILESYSPTR; (* link to next file system on chain *)
fsflags : lBITSET;
root : PROCEDURE (sINTEGER, VAR FCOOKIE): lINTEGER;
lookup : PROCEDURE (FCOOKIEPTR, VAR ARRAY OF CHAR, VAR FCOOKIE): lINTEGER;
creat : PROCEDURE (FCOOKIEPTR, REF ARRAY OF CHAR, sINTEGER,
sBITSET, VAR FCOOKIE): lINTEGER;
getdev : PROCEDURE (FCOOKIEPTR, ADDRESS) : DEVDRVPTR;
getxattr : PROCEDURE (FCOOKIEPTR, VAR XATTR): lINTEGER;
chattr : PROCEDURE (FCOOKIEPTR, sBITSET): lINTEGER;
chown : PROCEDURE (FCOOKIEPTR, sINTEGER, sINTEGER): lINTEGER;
chmode : PROCEDURE (FCOOKIEPTR, sINTEGER): lINTEGER;
mkdir : PROCEDURE (FCOOKIEPTR, REF ARRAY OF CHAR, sINTEGER): lINTEGER;
rmdir : PROCEDURE (FCOOKIEPTR, REF ARRAY OF CHAR): lINTEGER;
remove : PROCEDURE (FCOOKIEPTR, REF ARRAY OF CHAR): lINTEGER;
getname : PROCEDURE (FCOOKIEPTR, VAR FCOOKIE, VAR ARRAY OF CHAR): lINTEGER;
rename : PROCEDURE (FCOOKIEPTR, REF ARRAY OF CHAR, FCOOKIEPTR, REF ARRAY OF CHAR): lINTEGER;
opendir : PROCEDURE (VAR DIR, sINTEGER): lINTEGER;
readdir : PROCEDURE (DIRPTR, ADDRESS, sINTEGER, VAR FCOOKIE): lINTEGER;
rewinddir : PROCEDURE (DIRPTR): lINTEGER;
closedir : PROCEDURE (DIRPTR): lINTEGER;
pathconf : PROCEDURE (FCOOKIEPTR, sINTEGER): lINTEGER;
dfree : PROCEDURE (FCOOKIEPTR, ADDRESS);
writelabel : PROCEDURE (FCOOKIEPTR, REF ARRAY OF CHAR): lINTEGER;
readlabel : PROCEDURE (FCOOKIEPTR, VAR ARRAY OF CHAR, sINTEGER): lINTEGER;
symlink : PROCEDURE (FCOOKIEPTR, REF ARRAY OF CHAR, REF ARRAY OF CHAR): lINTEGER;
readlink : PROCEDURE (FCOOKIEPTR, VAR ARRAY OF CHAR, sINTEGER): lINTEGER;
hardlink : PROCEDURE (FCOOKIEPTR, REF ARRAY OF CHAR, FCOOKIEPTR, REF ARRAY OF CHAR): lINTEGER;
fscntl : PROCEDURE (FCOOKIEPTR, VAR ARRAY OF CHAR, sINTEGER, lINTEGER): lINTEGER;
dskchng : PROCEDURE (sINTEGER): lINTEGER;
zero : PROCEDURE (): lINTEGER;
END;
CONST
(* flags for open() modes *)
O_RWMODE = sBITSET(3); (* isolates file read/write mode *)
O_RDONLY = {} ;
O_WRONLY = Bit0 ;
O_RDWR = sBITSET(2);
O_EXEC = sBITSET(3); (* execute file; used by kernel only *)
O_APPEND = Bit3 ; (* all writes go to end of file *)
O_SHMODE = sBITSET($70) ; (* isolates file sharing mode *)
O_COMPAT = {}; (* compatibility mode *)
O_DENYRW = Bit4 ; (* deny both read and write access *)
O_DENYW = Bit5 ; (* deny write access to others *)
O_DENYR = sBITSET($30) ; (* deny read access to others *)
O_DENYNONE = Bit6 ; (* don't deny any access to others *)
O_NOINHERIT = Bit7 ; (* children don't get this file descriptor *)
O_NDELAY = Bit8 ; (* don't block for i/o on this file *)
O_CREAT = Bit9 ; (* create file if it doesn't exist *)
O_TRUNC = Bit10 ; (* truncate file to 0 bytes if it does exist *)
O_EXCL = Bit11 ; (* fail open if file exists *)
O_USER = sBITSET($0fff); (* isolates user-settable flag bits *)
O_GLOBAL = Bit12 ; (* for Fopen: opens a global file handle *)
(* kernel mode bits -- the user can't set these! *)
O_TTY = Bit13; (* FILEPTR refers to a terminal *)
O_HEAD = Bit14; (* FILEPTR is the master side of a fifo *)
O_LOCK = Bit15; (* FILEPTR has had locking Fcntl's performed *)
(* GEMDOS file attributes *)
(* macros to be applied to FILEPTRS to determine their type *)
(* is_terminal(f) (f->flags & O_TTY) *)
(* lseek() origins *)
SEEK_SET = 0; (* from beginning of file *)
SEEK_CUR = 1; (* from current location *)
SEEK_END = 2; (* from end of file *)
(* The requests for Dpathconf() *)
DP_IOPEN = 0; (* internal limit on # of open files *)
DP_MAXLINKS = 1; (* max number of hard links to a file *)
DP_PATHMAX = 2; (* max path name length *)
DP_NAMEMAX = 3; (* max length of an individual file name *)
DP_ATOMIC = 4; (* # of bytes that can be written atomically *)
DP_TRUNC = 5; (* file name truncation behavior *)
DP_NOTRUNC = 0; (* long filenames give an error *)
DP_AUTOTRUNC = 1; (* long filenames truncated *)
DP_DOSTRUNC = 2; (* DOS truncation rules in effect *)
DP_CASE = 6; (* file name case conversion behavior *)
DP_CASESENS = 0; (* case sensitive *)
DP_CASECONV = 1; (* case always converted *)
DP_CASEINSENS = 2; (* case insensitive, preserved *)
DP_MAXREQ = 6; (* highest legal request *)
(* Dpathconf and Sysconf return this when a value is not limited
(or is limited only by available memory) *)
UNLIMITED = $7fffffffL;
(* various character constants and defines for TTY's *)
MiNTEOF = $0000ff1a; (* 1a == ^Z *)
(* defines for tty_read *)
RAW = {};
COOKED = Bit0;
NOECHO = {};
ECHO = Bit1;
ESCSEQ = Bit2; (* cursor keys, etc. get escape sequences *)
(* constants for various Fcntl commands *)
(* constants for Fcntl calls *)
F_DUPFD = 0; (* handled by kernel *)
F_GETFD = 1; (* handled by kernel *)
F_SETFD = 2; (* handled by kernel *)
FD_CLOEXEC = 1; (* close on exec flag *)
F_GETFL = 3; (* handled by kernel *)
F_SETFL = 4; (* handled by kernel *)
F_GETLK = 5;
F_SETLK = 6;
FSTAT = $00004600; (* (('F'<< 8) | 0) (* handled by kernel *) *)
FIONREAD = $00004601; (* (('F'<< 8) | 1) *)
FIONWRITE = $00004602; (* (('F'<< 8) | 2) *)
TIOCGETP = $00005400; (* (('T'<< 8) | 0) *)
TIOCSETP = $00005401; (* (('T'<< 8) | 1) *)
TIOCSETN = TIOCSETP;
TIOCGETC = $00005402; (* (('T'<< 8) | 2) *)
TIOCSETC = $00005403; (* (('T'<< 8) | 3) *)
TIOCGLTC = $00005404; (* (('T'<< 8) | 4) *)
TIOCSLTC = $00005405; (* (('T'<< 8) | 5) *)
TIOCGPGRP = $00005406; (* (('T'<< 8) | 6) *)
TIOCSPGRP = $00005407; (* (('T'<< 8) | 7) *)
TIOCFLUSH = $00005408; (* (('T'<< 8) | 8) *)
TIOCSTOP = $00005409; (* (('T'<< 8) | 9) *)
TIOCSTART = $0000540A; (* (('T'<< 8) | 10) *)
TIOCGWINSZ = $0000540B; (* (('T'<< 8) | 11) *)
TIOCSWINSZ = $0000540C; (* (('T'<< 8) | 12) *)
TIOCGXKEY = $0000540D; (* (('T'<< 8) | 13) *)
TIOCSXKEY = $0000540E; (* (('T'<< 8) | 14) *)
PPROCADDR = $00005001; (* (('P'<< 8) | 1) *)
PBASEADDR = $00005002; (* (('P'<< 8) | 2) *)
PCTXTSIZE = $00005003; (* (('P'<< 8) | 3) *)
PSETFLAGS = $00005004; (* (('P'<< 8) | 4) *)
PGETFLAGS = $00005005; (* (('P'<< 8) | 5) *)
SHMGETBLK = $00004D00; (* (('M'<< 8) | 0) *)
SHMSETBLK = $00004D01; (* (('M'<< 8) | 1) *)
(* terminal control constants (tty.sg_flags) *)
T_CRMOD = Bit0; (* 0x0001 *)
T_CBREAK = Bit1; (* 0x0002 *)
T_ECHO = Bit2; (* 0x0004 *)
T_RAW = Bit3; (* 0x0010 *)
T_TOS = Bit4; (* 0x0080 *)
T_TOSTOP = Bit5; (* 0x0100 *)
T_XKEY = Bit6; (* 0x0200 (* Fread returns escape sequences for
cursor keys, etc. *) *)
(* the following are terminal status flags (tty.state) *)
(* (the low byte of tty.state indicates a part of an escape sequence still
* hasn't been read by Fread, and is an index into that escape sequence)
*)
TS_ESC = $00ff;
TS_HOLD = Bit12; (* 0x1000 (* hold (e.g. ^S/^Q) *) *)
TS_COOKED = Bit15; (* 0x8000 (* interpret control chars *) *)
(* defines and declarations for Dcntl operations *)
DEV_INSTALL = $de02;
DEV_NEWBIOS = $de01;
DEV_NEWTTY = $de00;
(* defines for TOS attribute bytes *)
FA_RDONLY = Bit0; (* 0x01 *)
FA_HIDDEN = Bit1; (* 0x02 *)
FA_SYSTEM = Bit2; (* 0x04 *)
FA_LABEL = Bit3; (* 0x08 *)
FA_DIR = Bit4; (* 0x10 *)
FA_CHANGED = Bit5; (* 0x20 *)
TYPE
tchars = RECORD
intrc : CHAR;
quitc : CHAR;
startc: CHAR;
stopc : CHAR;
eofc : CHAR;
brkc : CHAR;
END;
ltchars = RECORD
suspc : CHAR;
dsuspc : CHAR;
rprntc : CHAR;
flushc : CHAR;
werasc : CHAR;
lnextc : CHAR;
END;
sgttyb = RECORD
ispeed : CHAR;
ospeed : CHAR;
erase : CHAR;
kill : CHAR;
flags : sBITSET;
END;
winsize = RECORD
ws_row : sINTEGER;
ws_col : sINTEGER;
ws_xpixel : sINTEGER;
ws_ypixel : sINTEGER;
END;
xKey = RECORD
xk_num : sINTEGER;
xk_def : ARRAY [0..7] OF CHAR;
END;
xKeyPtr = POINTER TO ARRAY [0..$FFFF] OF xKey;
TTY = RECORD
pgrp : sINTEGER; (* process group of terminal *)
state : sINTEGER; (* terminal status, e.g. stopped *)
use_cnt : sINTEGER; (* number of times terminal is open *)
res1 : sINTEGER; (* reserved for future expansion *)
sg : sgttyb;
tc : tchars;
ltc : ltchars;
wsiz : winsize;
rsel : lINTEGER; (* selecting process for read *)
wsel : lINTEGER; (* selecting process for write *)
xkey : xKeyPtr; (* extended keyboard table *)
rsrvd : ARRAY [0..2] OF lINTEGER;
END;
ttyPtr = POINTER TO TTY;
devDescr= RECORD
driver : DEVDRVPTR;
dinfo : sINTEGER;
flags : sINTEGER;
tty : ttyPtr;
reserved: ARRAY [0..3] OF CHAR;
END;
END FileSys.